/********* weChartPay.m Cordova Plugin Implementation *******/
/**
 *
 *微信支付
 *
 */
#import <Cordova/CDV.h>
#import "WechatPayManager.h"

@interface weChartPay : CDVPlugin {
    // Member variables go here.
}

- (void)coolMethod:(CDVInvokedUrlCommand*)command;
@end

@implementation weChartPay

- (void)coolMethod:(CDVInvokedUrlCommand*)command
{
    
    NSString* produceOrder = [command.arguments objectAtIndex:0];
    
    MMGWeakSelf(weakSelf);
    __block CDVPluginResult* pluginResult = nil;
    [[WechatPayManager sharedWechatPayManager] payWithProduce:produceOrder completionBlock:^(NSString *returnKey, BOOL isFinished) {
        if (isFinished) {
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:returnKey];
        }else {
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:returnKey];
//            [SVProgressHUD showErrorWithStatus:returnKey];
        }
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
        });
    }];
}

@end
